package cn.saas.inputbox;

import android.os.Bundle;
import android.widget.EditText;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import butterknife.ButterKnife;
import cn.saas.inputbox.customkeyboard.BaseKeyboard;
import cn.saas.inputbox.customkeyboard.KeyboardIP;
import cn.saas.inputbox.customkeyboard.KeyboardIdentity;
import cn.saas.inputbox.customkeyboard.KeyboardNumber;
import cn.saas.inputbox.customkeyboard.KeyboardUtils;
import cn.saas.inputbox.customkeyboard.utils.IPUtils;
import cn.saas.inputbox.customkeyboard.utils.IdentityUtils;

public class MainActivity extends AppCompatActivity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        EditText et_1 = findViewById(R.id.et_1);
        EditText et_2 = findViewById(R.id.et_2);
        EditText et_3 = findViewById(R.id.et_3);
        EditText et_4 = findViewById(R.id.et_4);

        KeyboardIdentity keyboardIdentity = new KeyboardIdentity(this);
        KeyboardUtils.bindEditTextEvent(keyboardIdentity, et_1);
        KeyboardIP keyboardIP = new KeyboardIP(this);
        KeyboardUtils.bindEditTextEvent(keyboardIP, et_2);
        KeyboardNumber keyboardNumber = new KeyboardNumber(this);
        KeyboardUtils.bindEditTextEvent(keyboardNumber, et_3);
        KeyboardNumber keyboardNumberRandom = new KeyboardNumber(this, false, true);
        KeyboardUtils.bindEditTextEvent(keyboardNumberRandom, et_4);
        keyboardNumberRandom.setOnOkClick(() -> {
            Toast.makeText(getApplicationContext(), et_4.getText().toString(), Toast.LENGTH_SHORT).show();
        });
        keyboardNumberRandom.setOnCancelClick(() -> {
            Toast.makeText(getApplicationContext(), et_4.getText().toString(), Toast.LENGTH_SHORT).show();
        });


        keyboardIdentity.setOnOkClick(new BaseKeyboard.OnOkClick() {
            @Override
            public void onOkClick() {
                IdentityUtils identityUtils = new IdentityUtils();
                if (!identityUtils.isValidatedAllIdcard(et_1.getText().toString())) {
                    Toast.makeText(getApplicationContext(), "输入的身份证号不合法", Toast.LENGTH_SHORT).show();
                }
            }
        });
        keyboardIP.setOnOkClick(new BaseKeyboard.OnOkClick() {
            @Override
            public void onOkClick() {
                if (!IPUtils.isValidatedIPPort(et_2.getText().toString())) {
                    Toast.makeText(getApplicationContext(), "输入的IP不合法", Toast.LENGTH_SHORT).show();
                }
            }
        });

    }
}